/*
 * Copyright 2007 Brian Watkins
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

package bw.cal;

import java.io.Serializable;
import bw.util.Util;

public class CalendarEvent implements Serializable, Comparable
{
    public static final int DAY_EVENT = 1;
    public static final int WEEKLY_EVENT = 2;
    public static final int YEARLY_EVENT = 3;

    private int _type = -1; 
    private String _desc = null;
    private CalendarEventTime _time = null;

    public CalendarEvent ( int eventType, CalendarEventTime time, String eventDesc )
    {
        _type = eventType;
        _desc = eventDesc;
        _time = time;
    }

    public int getType () { return _type; }

    public String getDescription () { return ( _desc == null ? "" : _desc ); }

    public CalendarEventTime getTime () { return _time; }

    public boolean equals ( Object obj )
    {
        CalendarEvent evt = (CalendarEvent) obj;
        
        return ( ( getType() == evt.getType() ) &&
                 getTime().equals( evt.getTime() ) &&
                 getDescription().equals( evt.getDescription() ) );
    }

    public int compareTo ( Object obj )
    {
        CalendarEvent ce = (CalendarEvent) obj;

        return _time.compareTo( ce.getTime() );
    }

    public String toString ()
    {
        StringBuffer buf = new StringBuffer();

        buf.append( "<event type='" ).append( _type );
        buf.append( "' start='" ).append( _time.getStartTimeStr() );
        buf.append( "' end='" ).append( _time.getEndTimeStr() );
        buf.append( "'>" );
        buf.append( Util.XMLEscape( _desc ) );
        buf.append( "</event>" );

        return buf.toString();
    }
}